﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net.Sockets;
using System.IO;
using System.Net;

namespace POS
{
    public partial class Startup : DevExpress.XtraEditors.XtraForm
    {
        public static Thread StartupProcedures;


        public Startup()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void MainProgram_Load(object sender, EventArgs e)
        {
            progressPanel1.Description = "";
            StaticProperties.TimeToUpdate = 2.5;

            StartupProcedures = new Thread(new ThreadStart(Startup1));
            StartupProcedures.Name = "STARTUP THREAD";
            StartupProcedures.Start();


        }

        void Startup1()
        {
            progressPanel1.Caption = "";
            Thread.Sleep(250);
            try
            {
                progressPanel1.Caption = "Checking Network Connection";
                Thread.Sleep(250);
                if (DataTableClass.IsServerConnected())
                {
                    progressPanel1.Caption = "Loading Employee Data";
                    Thread.Sleep(125);
                    DataTableClass.LoadDataTable("EmployeeLogin", DataTableClass.EmployeeLogin);
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("EmployeeInfo", DataTableClass.EmployeeInfo);
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("EmployeeTimeSheet", DataTableClass.EmployeeTimeSheet);
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("JobTitles", DataTableClass.JobTitles);
                    //Thread.Sleep(250);

                    progressPanel1.Caption = "Loading Menu Items";
                    Thread.Sleep(125);
                    DataTableClass.LoadDataTable("MenuCategory", DataTableClass.MenuItemsCategory);
                    DataTableClass.LoadMenuCategoryDictionary();
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("MenuItems", DataTableClass.MenuItems);
                    DataTableClass.LoadMenuItemsDictionary();
                    //Thread.Sleep(250);
                    //DataTableClass.LoadDataTable("ModificationList", DataTableClass.ModificationList);
                    //Thread.Sleep(250);


                    progressPanel1.Caption = "Loading Receipt Data";
                    Thread.Sleep(125);
                    DataTableClass.LoadDataTable("Receipt", DataTableClass.Receipt);
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("ReceiptData", DataTableClass.ReceiptData);
                    //Thread.Sleep(250);
                    DataTableClass.LoadDataTable("PaymentTypes", DataTableClass.PaymentTypes);
                    //Thread.Sleep(250);
                    StaticProperties.StartingReceiptNo = 100;
                    //MessageBox.Show(StaticProperties.ReceiptNoGenerator());


                    progressPanel1.Caption = "Loading Table Chart";
                    Thread.Sleep(125);
                    //MessageBox.Show("DONE");
                }
            }
            catch
            {

            }
            finally
            {
                //DataTableClass.SaveDataSetToFile(DataTableClass.PaymentTypes);

                //foreach(DataTable data in DataTableClass.POS.Tables)
                //{
                //    string tablename = data.TableName;

                //    DataTableClass.SendDataToSqlServer(data);
                //}

                Thread.Sleep(500);
                this.Close();
            }
        }



        private void timer1_Tick(object sender, EventArgs e)
        {
            
        }


    }
}
